var t = getApp();

Page({
    data: {
        appointmentLang: {},
        status: "1",
        category: {},
        show1: !1,
        show2: !1,
        className: [],
        url: "",
        json: {},
        sort: "asc",
        point: {},
        kwd: "",
        projectList: [],
        isLoadMore: !0,
        page: 1,
        total_page: 0
    },
    onLoad: function(t) {
        this.setData({
            appointmentLang: wx.getStorageSync("yz_basic_info").lang.appointment,
            city: t.city,
            point: JSON.parse(t.point)
        }), wx.setNavigationBarTitle({
            title: "搜索" + this.data.appointmentLang.project + "/" + this.data.appointmentLang.worker
        }), this.init(), this.getClass(), this.getData();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {},
    goProject: function(t) {
        var a = t.currentTarget.dataset.id, s = JSON.stringify(this.data.point);
        wx.navigateTo({
            url: "/packageE/appointment/ProjectDetails/ProjectDetails?project_id=" + a + "&point=" + s
        });
    },
    toTechnicianDetails: function(t) {
        var a = t.currentTarget.dataset.id, s = JSON.stringify(this.data.point);
        wx.navigateTo({
            url: "/packageE/appointment/technician_details/technician_details?worker_id=" + a + "&point=" + s
        });
    },
    bind: function(t) {
        this.setData({
            kwd: t.detail.value
        });
    },
    goBack: function() {
        getCurrentPages().length <= 1 ? wx.reLaunch({
            url: "/packageG/index/index"
        }) : wx.navigateBack({
            delta: 1
        });
    },
    getClass: function() {
        var a = this, s = t.getNetAddresss("plugin.appointment.frontend.project-category.get-list");
        t._getNetWork({
            url: s,
            data: {},
            success: function(t) {
                var s = t.data;
                1 == s.result ? a.setData({
                    className: s.data
                }) : wx.showToast({
                    icon: "none",
                    title: s.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    close: function() {
        this.setData({
            show1: !1
        });
    },
    evaluateBtn: function() {
        "asc" == this.data.sort ? this.setData({
            sort: "desc"
        }) : this.setData({
            sort: "asc"
        }), this.setData({
            page: 1,
            isLoadMore: !0,
            total_page: 0,
            show1: !1
        }), this.getData();
    },
    selectType: function(t) {
        var a = t.currentTarget.dataset.type;
        a != this.data.status ? (this.setData({
            status: a,
            projectList: []
        }), this.getData(), "2" === this.data.status && this.setData({
            category: {}
        }), this.setData({
            show2: !1
        })) : this.setData({
            show2: !1
        });
    },
    showProject: function() {
        this.setData({
            show1: !1,
            show2: !this.data.show2
        });
    },
    showClass: function() {
        "2" !== this.data.status && this.setData({
            show2: !1,
            show1: !this.data.show1
        });
    },
    init: function() {
        this.setData({
            projectList: [],
            kwd: "",
            category: {},
            status: "1",
            show1: !1,
            show2: !1,
            sort: "asc",
            isLoadMore: !0,
            total_page: 0,
            "json.page": 1
        });
    },
    selectionBtn: function(t) {
        var a = t.currentTarget.dataset.item;
        a.name ? this.setData({
            category: a
        }) : this.setData({
            category: {}
        }), this.setData({
            page: 1,
            isLoadMore: !0,
            total_page: 0,
            show1: !1
        }), this.getData();
    },
    getData: function() {
        var a = this;
        this.setData({
            json: {}
        }), "1" === this.data.status ? this.setData({
            "json.sort": this.data.sort,
            "json.category_id": this.data.category.id,
            "json.name": this.data.kwd,
            "json.page": 1,
            url: t.getNetAddresss("plugin.appointment.frontend.project.get-list")
        }) : this.setData({
            "json.lng": this.data.point.lng,
            "json.lat": this.data.point.lat,
            "json.city_name": this.data.city,
            "json.kwd": this.data.kwd,
            "json.page": 1,
            url: t.getNetAddresss("plugin.appointment.frontend.worker.get-workers-by-name")
        }), t._getNetWork({
            url: this.data.url,
            data: this.data.json,
            success: function(t) {
                var s = t.data;
                1 == s.result ? (a.setData({
                    isLoadMore: !0,
                    total_page: s.data.last_page,
                    projectList: s.data.data
                }), a.data.total_page || a.setData({
                    total_page: 0
                })) : wx.showToast({
                    title: s.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMoreData: function() {
        var a = this;
        if (this.setData({
            isLoadMore: !1
        }), !(this.data.page >= this.data.total_page)) {
            var s = this.data.page + 1;
            this.setData({
                page: s
            }), t._getNetWork({
                url: this.data.url,
                data: this.data.json,
                success: function(t) {
                    var s = t.data;
                    if (1 == s.result) {
                        var e = s.data.data.concat(a.data.projectList);
                        a.setData({
                            projectList: e
                        });
                    } else {
                        wx.showToast({
                            title: s.msg,
                            icon: "none"
                        });
                        var o = a.data.page - 1;
                        a.setData({
                            page: o,
                            isLoadMore: !1
                        });
                    }
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    }
});